home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / mint / mint104s.zoo / mint.src / syscall.spp < prev    next >
Text File  |  1993-03-08  |  13KB  |  458 lines

  1. ; Copyright 1992 Eric R. Smith
  2. ; Copyright 1992,1993 Atari Corporation
  3. ; All rights reserved.
  4.  
  5. %include "magic.i"
  6. ;
  7. ; syscall: interface for system calls. The following entry points are
  8. ;    defined:
  9. ; _mint_bios:  entry point for the BIOS calls (trap #13)
  10. ; _mint_xbios: entry point for XBIOS calls (trap #14)
  11. ; _mint_dos:   entry point for GEMDOS calls (trap #1)
  12. ; _sig_return: user signal handlers return to this routine (see signal.c)
  13. ;              it is responsible for restoring the kernel's old context
  14. ;              via the Psigreturn() system call
  15. ; _lineA0:     calls the line A initialize routine
  16. ; _call_aes:   calls the GEM AES
  17. ; _do_usrcall: calls a user supplied function (e.g. for Supexec), with
  18. ;           arguments supplied from global variables usrarg1, usrarg2, etc.
  19. ; _callout:    calls an external function, after first saving all registers,
  20. ;              and restores the registers afterward
  21. ;
  22. ; external variables referenced:
  23. ; _bios_tab, _bios_max:
  24. ;    table of entry points for BIOS routines, max # of routine
  25. ; _xbios_tab, _xbios_max:
  26. ;    ditto for XBIOS
  27. ; _dos_tab, _dos_max:
  28. ;    ditto for GEMDOS
  29. ; _curproc:
  30. ;    pointer to current process table entry, and hence to save area for
  31. ;    context (this is always the first entry in the PROC table).
  32. ; _valid_return:
  33. ;    used to indicate to the kernel that a valid return from user mode
  34. ;    is taking place
  35. ;
  36. ; _bconbuf, _bconbsiz, _bconbdev:
  37. ;    256 byte buffer for Bconout() output. If _bconbsiz is non-zero,
  38. ;    there are that many bytes in _bconbuf waiting to be flushed. The
  39. ;    output is for device _bconbdev.
  40. ;
  41. ; The C function enter_kernel() is called on entry to the kernel, and the
  42. ; function leave_kernel() is called on exit. These functions are responsible
  43. ; for saving and restoring the various trap vectors, so that MiNT can trap
  44. ; out to TOS directly, but programs can only trap to MiNT.
  45. ;
  46. ; we also call certain BIOS functions directly if these are known not to
  47. ; require saving/restoring of context
  48. ;
  49.     TEXT
  50.     
  51.     XDEF    _mint_bios,_mint_xbios
  52.     XDEF    _mint_dos
  53.     XREF    _build_context
  54.     XREF    _restore_context
  55.     XREF    _proc_clock        ; controls process' allocation of CPU time
  56.     XREF    _enter_kernel
  57.     XREF    _leave_kernel
  58.     XREF    _preempt
  59.  
  60.     XREF    _curproc
  61.     XREF    _bios_tab,_bios_max
  62.     XREF    _xbios_tab,_xbios_max,_old_xbios
  63.     XREF    _dos_tab,_dos_max
  64.  
  65.     XREF    _bconbuf,_bconbsiz,_bconbdev
  66.     XREF    _bflush
  67.  
  68.     XREF    _ubconstat,_do_bconin,_ubcostat,_kbshift
  69.     
  70. _mint_dos:
  71.     clr.w    -(sp)            ; no frame format needed
  72.     move.l    _curproc,d0
  73.     addq.l    #4,d0
  74.     move.l    d0,-(sp)        ; push pointer to syscall context save
  75.     jsr    _build_context
  76.     move.l    #_dos_tab,a5        ; set syscall_tab
  77.     move.w    _dos_max,d5        ; set syscall_max
  78. ;
  79. ; copy parameters onto process stack. a0 and a1 were set by _build_context
  80. ;
  81.  
  82.     move.l    _curproc,a0
  83.     move.l    (a0),sp            ; this puts us in our private stack
  84.     move.l    24(a1),-(sp)        ; a1 was set by build_context
  85.     move.l    20(a1),-(sp)
  86.     move.l    16(a1),-(sp)
  87.     move.l    12(a1),-(sp)
  88.     move.l    8(a1),-(sp)
  89.     move.l    4(a1),-(sp)
  90.     move.l    (a1),-(sp)
  91.     jsr    _enter_kernel        ; set up vectors appropriately
  92.     bra    _syscall
  93.  
  94. _mint_xbios:
  95. ;
  96. ; Kludge for Setscreen: under Falcon TOS, this
  97. ; calls a GEMDOS function (Srealloc) and so
  98. ; we must *not* change any of the vectors!!
  99.  
  100.     btst    #13,(sp)        ; test for user/super mode
  101.     beq    LX_usr
  102. %ifdef ONLY030
  103.     lea    8(sp),a1
  104. %else
  105.     lea    6(sp),a1        ; supervisor mode: args on stack
  106.     tst.w    ($59e).w        ; test longframe
  107.     beq.s    LX_check
  108.     addq.l    #2,a1            ; stack is a bit bigger
  109. %endif
  110.     bra.s    LX_check
  111. LX_usr:
  112.     move.l    usp,a1            ; user mode: args on user stack
  113. LX_check:
  114.     move.w    (a1),d0            ; check command
  115.     cmp.w    #5,d0            ; Setscreen?
  116.     beq    LX_screen        ; no -- fall through
  117.  
  118.     clr.w    -(sp)            ; no frame format needed
  119.     move.l    _curproc,d0
  120.     addq.l    #4,d0
  121.     move.l    d0,-(sp)        ; push pointer to syscall context save
  122.     jsr    _build_context
  123.     move.l    #_xbios_tab,a5        ; set syscall_tab
  124.     move.w    _xbios_max,d5        ; set syscall_max
  125. ;
  126. ; copy parameters onto process stack. a0 and a1 were set by _build_context
  127. ;
  128.  
  129.     move.l    _curproc,a0
  130.     move.l    (a0),sp            ; this puts us in our private stack
  131.     move.l    24(a1),-(sp)        ; a1 was set by build_context
  132.     move.l    20(a1),-(sp)
  133.     move.l    16(a1),-(sp)
  134.     move.l    12(a1),-(sp)
  135.     move.l    8(a1),-(sp)
  136.     move.l    4(a1),-(sp)
  137.     move.l    (a1),-(sp)
  138.     jsr    _enter_kernel        ; set up vectors appropriately
  139.     bra    _syscall
  140. ;
  141. ; For setscreen, jump directly to the ROM vector --
  142. ; this avoids all hazards (like changing the vectors)
  143.  
  144. LX_screen:
  145.     move.l    _old_xbios+8,a0
  146.     jmp    (a0)
  147.  
  148.  
  149. _mint_bios:
  150. ;
  151. ; Entering the kernel can be very expensive; so, we take a short-cut
  152. ; if possible -- we try some BIOS functions out, and if they
  153. ; succeed without blocking then we're done; otherwise, we go
  154. ; through the long procedure for entering the kernel
  155. ;
  156. ; These shortcuts aren't done when we're called in supervisor mode,
  157. ; because TOS uses very tiny stacks (smaller than we want); the
  158. ; shortcuts operate on the user-supplied ssp, whereas the "full"
  159. ; BIOS code works on our (private) system stack
  160. ;
  161. ; the shortcuts are also turned off if BIOSBUF=n
  162. ;
  163.     jsr    _enter_kernel        ; set up BIOS vectors
  164.     tst.w    _bconbdev        ; is BIOS buffering on?
  165.     bmi    L_bios            ; no; skip all this
  166.  
  167.     btst    #5,(sp)            ; test for user/super mode
  168.     bne.s    L_bios            ; if super, goto L_bios
  169.     tst.w    _proc_clock        ; are we about to be preempted?
  170.     beq    L_bios
  171.  
  172.     move.l    usp,a1            ; user mode: args on user stack
  173. L_ubios:
  174.     move.w    (a1),d0            ; get command
  175.     cmp.w    #3,d0            ; Bconout?
  176.     beq    do_bconout        ; yes -- go do it
  177. ;
  178. ; most of the remaining functions require BIOS vectors to be properly
  179. ; set up
  180.     tst.w    _bconbsiz        ; is BIOS output waiting?
  181.     bne.s    L_bios            ; yes -- do regular code
  182.  
  183. ; test for various BIOS functions
  184.     cmp.w    #1,d0            ; Bconstat?
  185.     bne.s    L_00
  186.     move.w    2(a1),-(sp)        ; push arg
  187.     jsr    _ubconstat
  188. L_1out:
  189.     addq.l    #2,sp
  190. L_0out:
  191.     move.l    d0,-(sp)        ; save d0
  192.     ori.w    #$0700,sr        ; spl7()
  193.     jsr    _leave_kernel
  194.     move.l    (sp)+,d0        ; retrieve value to be returned
  195.     rte                ; return to user
  196. L_00:
  197.     cmp.w    #2,d0            ; Bconin?
  198.     bne.s    L_01
  199.     move.w    2(a1),-(sp)        ; yes; push argument
  200.     jsr    _do_bconin
  201.     addq.l    #2,sp
  202.     cmp.w    #$dead,d0        ; would Bconin block?
  203.     bne.s    L_0out            ; no -- we're done
  204.     bra.s    L_bios            ; yes -- do the long stuff
  205. L_01:
  206.     cmp.w    #8,d0            ; Bcostat?
  207.     bne.s    L_02
  208.     move.w    2(a1),-(sp)        ; push device
  209.     jsr    _ubcostat        ; get status
  210.     bra.s    L_1out
  211. L_02:
  212.     cmp.w    #11,d0            ; Kbshift?
  213.     bne.s    L_bios
  214.     move.w    2(a1),-(sp)        ; push arg
  215.     jsr    _kbshift
  216.     bra.s    L_1out
  217.  
  218. L_bios:
  219.     clr.w    -(sp)            ; no frame format needed
  220.     move.l    _curproc,d0
  221.     addq.l    #4,d0
  222.     move.l    d0,-(sp)        ; push pointer to syscall context save
  223.     jsr    _build_context
  224.     move.l    #_bios_tab,a5        ; set syscall_tab
  225.     move.w    _bios_max,d5        ; set syscall_max
  226. ;
  227. ; copy parameters onto process stack. a0 and a1 were set by _build_context
  228. ;
  229.  
  230.     move.l    _curproc,a0
  231.     move.l    (a0),sp            ; this puts us in our private stack
  232.     move.l    24(a1),-(sp)        ; a1 was set by build_context
  233.     move.l    20(a1),-(sp)
  234.     move.l    16(a1),-(sp)
  235.     move.l    12(a1),-(sp)
  236.     move.l    8(a1),-(sp)
  237.     move.l    4(a1),-(sp)
  238.     move.l    (a1),-(sp)
  239.  
  240. _syscall:
  241. ;
  242. ; check here to see if we need to flush the Bconout() buffer
  243. ;
  244.     tst.w    _bconbsiz        ; characters in buffer?
  245.     beq.s    L_noflush        ; no: OK to proceed
  246. ;
  247. ; watch out, this could cause a context switch
  248. ;
  249.     jsr    _bflush            ; flush the buffer
  250.  
  251. L_noflush:
  252. ;
  253. ; figure out which routine to call
  254. ;
  255.     move.w    (sp),d0
  256.     cmp.w    #-1,d0            ; trapping with -1 means return
  257.     bne.s    check_max        ; the corresponding system table
  258.     move.l    a5,d0
  259.     bra.s    out
  260. check_max:
  261.     cmp.w    d5,d0
  262.     bge.s    error
  263.     add.w    d0,d0
  264.     add.w    d0,d0            ; multiply by 4
  265.     move.l    0(a5,d0.w),d0        ; d0 = syscall_tab[d0]
  266.     beq.s    error            ; null entry means invalid call
  267.     addq.l    #2,sp            ; pop function number off stack
  268.     move.l    d0,a0
  269.     jsr    (a0)            ; go do the call
  270. out:
  271.     move.l    _curproc,a0
  272.     move.l    d0,P_SYSCTXT+C_D0(a0)    ; set d0 in the saved context
  273.     move.w    P_SYSCTXT+C_SR(a0),d0    ; get saved status register
  274.     
  275.     tst.l    P_PTRACER(a0)        ; check curproc->ptracer, if not set
  276.     beq.s    notrace            ; then no pending trace; this ensures
  277.     move.w    d0,d1            ; we work with non-MiNT debuggers
  278.     and.w    #$c000,d1        ; are eith